<?php
class cls_data_search extends cls_data_base
{
	function keywords_search($query_type,$query,$sort_name,$sort_order)
	{
		$query_type=mysql_escape_string($query_type);
		$query=mysql_escape_string($query);
		
		$sql="SELECT * FROM product p WHERE {$query_type} like '%{$query}%'
				order by {$sort_name} {$sort_order}";
		$re=$this->db->getAll($sql);
		return $re;
		
	}
	
	function discount_search($discount_id,$sort_name,$sort_order)
	{
		$discount_id=mysql_escape_string($discount_id);
		$sql="SELECT p.* FROM discount d,product p,discountproduct dp WHERE p.id=dp.productid and d.id=dp.discountid and d.id={$discount_id}
				order by {$sort_name} {$sort_order}";
		$re=$this->db->getAll($sql);
		return $re;
	}
	
	function discount_info($discount_id)
	{
		$discount_id=mysql_escape_string($discount_id);
		$sql="select * from discount where id={$discount_id}";
		$re=$this->db->getRow($sql);
		return $re;
	}
	
	function available_discount()
	{
		$sql="select * from discount where status=1 and (discounttype=1 or discounttype=2)";
		$re=$this->db->getAll($sql);
		return $re;
	}
	
	function get_product_discount($product_id)
	{
		$product_id=mysql_escape_string($product_id);
		$sql="select d.* fro
		discountproduct dp,discount d
		where d.ID = dp.DiscountID and dp.productid='{$product_id}'";
		$product_discount=$this->db->getrow($sql);
		return $product_discount;
	}
	
	function get_product_info($product_id)       /*杈撳叆浜у搧id锛�杈撳嚭product琛ㄩ噷鐨勫叧浜庤浜у搧鐨勬墍鏈変俊鎭�*/
	{
		$product_id=mysql_escape_string($product_id);
		$sql="select p.*,ps.Quantity,pm.productcomment
		from product p
		left join productstatistic ps on p.ID=ps.productID
		left join productcomment pm on p.ID=pm.productID
		where p.ID='{$product_id}'";
		$product_detail=$this->db->getrow($sql);
		return $product_detail;
	}
	
}